package com.hghivln.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hghivln.mapper.OperLogMapper;
import com.hghivln.pojo.domain.OperLog;
import com.hghivln.pojo.dto.OperLogDto;
import com.hghivln.pojo.vo.AjaxResult;
import com.hghivln.service.OperLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

@Service
public class OperLogServiceImpl implements OperLogService{

    @Autowired
    private OperLogMapper operLogMapper;

    @Override
    public AjaxResult listForPage(OperLogDto operLogDto) {
        Page<OperLog> page = new Page<>(operLogDto.getPageNum(), operLogDto.getPageSize());
        QueryWrapper<OperLog> qw = new QueryWrapper<>();
        qw.like(StringUtils.isNotBlank(operLogDto.getTitle()),OperLog.COL_TITLE,operLogDto.getTitle());
        qw.like(StringUtils.isNotBlank(operLogDto.getOperName()),OperLog.COL_OPER_NAME,operLogDto.getOperName());
        qw.like(StringUtils.isNotBlank(operLogDto.getStatus()),OperLog.COL_STATUS,operLogDto.getStatus());
        qw.eq(StringUtils.isNotBlank(operLogDto.getBusinessType()),OperLog.COL_BUSINESS_TYPE,operLogDto.getBusinessType());

        qw.ge(operLogDto.getBeginTime() != null,OperLog.COL_OPER_TIME,operLogDto.getBeginTime());
        qw.le(operLogDto.getEndTime() != null,OperLog.COL_OPER_TIME,operLogDto.getEndTime());
        operLogMapper.selectPage(page,qw);
        return AjaxResult.success("查询成功",page.getRecords(),page.getTotal());
    }

    @Override
    public int deleteOperLogByIds(Long[] ids) {
        List<Long> list = Arrays.asList(ids);
        return operLogMapper.deleteBatchIds(list);
    }

    @Override
    public int clearAllOperLog() {
        return operLogMapper.delete(null);
    }

    @Override
    public void insertOperLog(OperLog operLog) {
        operLogMapper.insert(operLog);
    }
}
